/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package libreriaTicket.dao;

import conexion.BD;
import conexion.SqlFormat;
import java.util.ArrayList;
import libreriaTicket.entity.Pais;
import libreriaTicket.entity.Ticket;

/**
 *
 * @author CITT-2013
 */
public class DaoTicket {
    
    public static boolean sqlInsert(Ticket ticket) {
        try {
            SqlFormat sql = new SqlFormat(SqlFormat.INSERTAR, "ticket");
            //sql.addField("codigo", ticket.getIdTicket());
            sql.addField("precio", ticket.getPrecio());
            sql.addField("id_evento", ticket.getEvento().getIdEvento());//---Siempre sera 1, ya que siempre sera chile
            sql.addField("fecha_emision", ticket.getEvento().getIdEvento());
            
            
            return BD.getInstance().sqlEjecutar(sql.crearInstruccion());



        } catch (Exception e) {
        }
        return false;
    }

    public static boolean sqlUpdate(Ticket ticket) {
        try {

            SqlFormat sql = new SqlFormat(SqlFormat.ACTUALIZAR, "ticket");
            sql.where("id", ticket.getIdTicket());
            sql.addField("precio", ticket.getPrecio());
            sql.addField("id_evento", ticket.getEvento().getIdEvento());//---Siempre sera 1, ya que siempre sera chile
            sql.addField("fecha_emision", ticket.getFecha_emision());//---Siempre sera 1, ya que siempre sera chile
           
            return BD.getInstance().sqlEjecutar(sql.crearInstruccion());


        } catch (Exception e) {
        }
        return false;
    }

    public static boolean sqlDelete(Ticket ticket) {
        try {
            SqlFormat sql = new SqlFormat(SqlFormat.ELIMINAR, "ticket");
            sql.where("id", ticket.getIdTicket());

            return BD.getInstance().sqlEjecutar(sql.crearInstruccion());


        } catch (Exception e) {
        }
        return false;
    }

    public static Ticket sqlSelect(Ticket ticket) {

        try {
            Ticket ticket2 = new Ticket();
            SqlFormat sql = new SqlFormat(SqlFormat.SELECCIONAR, "ticket");
            sql.where("ticket", ticket.getIdTicket());

            BD.getInstance().sqlQuery(sql.crearInstruccion());
            if (!BD.getInstance().sqlFetch()) {
                return null;
            }

            ticket2.setPrecio(BD.getInstance().getInt("precio"));
            ticket2.setIdTicket(BD.getInstance().getInt("id"));
            ticket2.setFecha_emision(BD.getInstance().getString("fecha_emision"));
            
            


            return ticket2;
        } catch (Exception e) {
        }
        return null;
    }
/*
    public static ArrayList<Ticket> sqlSelectAll() {
        ArrayList<Ticket> tickets = new ArrayList<Ticket>();


        try {
            BD.getInstance().sqlQuery(SqlFormat.SelectAll("ticket"));
            while (BD.getInstance().sqlFetch()) {
                Ticket ticket = new Ticket();
                ticket.setDescripcion(BD.getInstance().getString("descripcion"));
                ticket.setIdTicket(BD.getInstance().getInt("codigo"));
                ticket.setPais(new Pais(BD.getInstance().getString("codPais")));
                
                tickets.add(ticket);

            }
            return tickets;
        } catch (Exception e) {
        }
        return null;
    }
    */
}
